//声明: 该文件需要 swiper,jqueryui,common,toast,jquery

require(["config"], function(config) {
	require(["poplayer","com", "jquery", "sw", "fly",], function(poplayer,com, $, sw, fly) {
		//修改名字
		if(getCookie("names").length==0){
			
		}else{
			$("#myname").html(getCookie("names"));
		}
		
		
			//弹出框，想要获取数据
			poplayer.alert($('#position'))
		$(".layui-layer-btn0").click(function(){
			var txt = $("#position").val();
			if(txt.length==0){
				$("#positions").html();
			}else{
				$("#positions").html(txt);
			}
		})
			
		//购物车
		$(function() {
			var offset = $("#end").offset();
			$(".addcar").click(function(event) {
				var num = parseInt($("#shoppingnum").html()) + 1;

				setCookie("num", num, 10);

				$(this).css("background", "gainsboro");
				var addcar = $(this);
				var img = addcar.parent().find('img').attr('src');
				var flyer = $('<img id="u-flyer" class="u-flyers" src="' + img + '">');
				flyer.fly({
					start: {
						left: event.clientX,
						top: event.clientY
					},
					end: {
						left: offset.left,
						top: 340,
						width: 0,
						height: 0
					},
					onEnd: function() {
						var num = parseInt($("#shoppingnum").html()) + 1;
						$("#shoppingnum").html(num);
						$("#msg").show().animate({ width: '250px' }, 200).fadeOut(1000);
						//	addcar.css("cursor", "default").removeClass('orange').unbind('click');
						//this.destory();
					}
				});
			});

			var pre = document.getElementById("pre");
			var con = document.getElementById("con");
			var arr = "";
			pre.onkeydown = function(evt) {
				if(evt.keyCode == 40 || evt.keyCode == 38) {
					pre.onkeydown = "";
				}
				//拿到用户键入的数据
				var key = document.getElementById("pre").value;
				jsonp(key);
				//定义一个变量拿到用户接收的数据
				var shujv;
				//创建一个对象
				var req = new XMLHttpRequest();
			}
		});
		//导航
		(function() {

			var $subblock = $(".subpage"),
				$head = $subblock.find('h2'),
				$ul = $("#proinfo"),
				$lis = $ul.find("li"),
				inter = false;
			$lis.hover(function() {
				if(!$(this).hasClass('nochild')) {
					$(this).addClass("prosahover");
					$(this).find(".prosmore").removeClass('hide');
				}
			}, function() {
				if(!$(this).hasClass('nochild')) {
					if($(this).hasClass("prosahover")) {
						$(this).removeClass("prosahover");
					}
					$(this).find(".prosmore").addClass('hide');
				}
			});
			//轮播图
			var mySwiper = new Swiper('.swiper-container', {
				autoplay: 3000, //可选选项，自动滑动
				pagination: '.swiper-pagination',
				paginationClickable: true,
				keyboardControl: true,
				autoplayDisableOnInteraction: false,

			})
			//brand
			//白酒
			var bai = Array.from(document.getElementById("brand name").children);

			bai[0].onmousemove = function() {
				$(".brand_white").css("display", "block");
				$(".brand_local").css("display", "none");
				$(".brand_red").css("display", "none");
			}
			bai[1].onmousemove = function() {
				$(".brand_white").css("display", "none");
				$(".brand_local").css("display", "block");
				$(".brand_red").css("display", "none");
			}
			bai[2].onmousemove = function() {
				$(".brand_white").css("display", "none");
				$(".brand_local").css("display", "none");
				$(".brand_red").css("display", "block");
			}

		})();

		//疯狂抢购
		var recommendlist = $(".recommend_con a");
		var recommendcontent = $(".recommend_content li");
		//遍历
		recommendlist.each(function(index) {
			recommendlist.index = index;
			recommendlist[index].onmousemove = function() {
				//先让所有的全部隐藏
				recommendcontent.each(function(index) {
					recommendcontent[index].style.display = "none";
				})
				recommendcontent[index].style.display = "block";
			}
		})

		//一楼
		var oneF1 = $(".oneF-1 ul li");
		var oneF2 = $(".oneF-2");
		oneF1.each(function(index) {
			oneF1.index = index;
			oneF1[index].onmousemove = function() {
				oneF2.each(function(index) {
					oneF2[index].style.display = "none";
				})
				oneF2[index].style.display = "block";
			}
		})

		//二楼
		var twoF1 = $(".twoF-1 ul li");
		var twoF2 = $(".twoF-2");
		twoF1.each(function(index) {
			twoF1.index = index;
			twoF1[index].onmousemove = function() {
				twoF2.each(function(index) {
					twoF2[index].style.display = "none";
				})
				twoF2[index].style.display = "block";
			}
		})

		//三楼
		var threeF1 = $(".threeF-1 ul li");
		var threeF2 = $(".threeF-2");
		threeF1.each(function(index) {
			threeF1.index = index;
			threeF1[index].onmousemove = function() {
				threeF2.each(function(index) {
					threeF2[index].style.display = "none";
				})
				threeF2[index].style.display = "block";
			}
		})

		//四楼
		var fourF1 = $(".fourF-1 ul li");
		var fourF2 = $(".fourF-2");
		fourF1.each(function(index) {
			fourF1.index = index;
			fourF1[index].onmousemove = function() {
				fourF2.each(function(index) {
					fourF2[index].style.display = "none";
				})
				fourF2[index].style.display = "block";
			}
		})

		//五楼
		var fiveF1 = $(".fiveF-1 ul li");
		var fiveF2 = $(".fiveF-2");
		fiveF1.each(function(index) {
			fiveF1.index = index;
			fiveF1[index].onmousemove = function() {
				fiveF2.each(function(index) {
					fiveF2[index].style.display = "none";
				})
				fiveF2[index].style.display = "block";
			}
		})

		//六楼
		var sixF1 = $(".sixF-1 ul li");
		var sixF2 = $(".sixF-2");
		sixF1.each(function(index) {
			sixF1.index = index;
			sixF1[index].onmousemove = function() {
				sixF2.each(function(index) {
					sixF2[index].style.display = "none";
				})
				sixF2[index].style.display = "block";
			}
		})

		//七楼
		var sevenF1 = $(".sevenF-1 ul li");
		var sevenF2 = $(".sevenF-2");
		sevenF1.each(function(index) {
			sevenF1.index = index;
			sevenF1[index].onmousemove = function() {
				sevenF2.each(function(index) {
					sevenF2[index].style.display = "none";
				})
				sevenF2[index].style.display = "block";
			}
		})

		//八楼
		var eightF1 = $(".eightF-1 ul li");
		var eightF2 = $(".eightF-2");
		eightF1.each(function(index) {
			eightF1.index = index;
			eightF1[index].onmousemove = function() {
				eightF2.each(function(index) {
					eightF2[index].style.display = "none";
				})
				eightF2[index].style.display = "block";
			}
		})

		//我的信息
		$(document).ready(function() {
			//    nav-li hover e
			var num;
			$("#li-1").hover(function() {
				//console.log("hah")
				/*图标向上旋转*/
				//	$(this).children().removeClass().addClass('hover-up');
				/*下拉框出现*/
				//var Obj = $(this).attr('id');
				//num = Obj.substring(3, Obj.length);
				//$('#box-' + num).slideDown(300);
				$(".hidden-box").show()
			}, function() {
				/*图标向下旋转*/
				//$(this).children().removeClass().addClass('hover-down');
				/*下拉框消失*/
				$(".hidden-box").hide();
				//$('#box-' + num).hide();
			});
			//    hidden-box hover e
			$('.hidden-box').hover(function() {
				/*保持图标向上*/
				//$('#li-' + num).children().removeClass().addClass('hover-up');
				$(this).show();
			}, function() {
				$(this).hide();
			});
		});

		//我的收藏
		$(document).ready(function() {

			$("#li-2").hover(function() {

				$('.hidden-box2').show();
			}, function() {
				/*图标向下旋转*/

				$('.hidden-box2').hide();;
			});

			$('.hidden-box2').hover(function() {

				$(this).show();
			}, function() {
				$(this).hide();
			});
		});

		//楼梯
		$(function() {
			var _index = 0;
			$("#menu ul li").click(function() {
				$(this).find("span").addClass("active").parent().siblings().find("span").removeClass("active");
				_index = $(this).index() + 1;
				//通过拼接字符串获取元素，再取得相对于文档的高度
				var _top = $("#louti" + _index).offset().top;
				//scrollTop滚动到对应高度
				$("body,html").animate({ scrollTop: _top }, 500);
			});
			var nav = $("#menu"); //得到导航对象
			var win = $(window); //得到窗口对象
			var sc = $(document); //得到document文档对象。
			win.scroll(function() {

				if(sc.scrollTop() >= 1500) {
					$("#menu").show();
					//获取滚动元素对应的索引!!!重难点
					var index = Math.floor(sc.scrollTop() / 800);

					$("#menu ul li span").eq(index - 1).addClass("active").parent().siblings().find("span").removeClass("active");
				} else {
					$("#menu").hide();
				}
			});
		});
		//几楼？

		//存储cookie
		//console.log( getCookie("username") );

		function setCookie(key, val, expires) {
			var now = new Date();
			now.setDate(now.getDate() + expires);
			document.cookie = key + "=" + val + "; expires=" + now;
		}

		function getCookie(key) {
			var cookiestr = document.cookie;
			var list = cookiestr.split("; ");
			for(var attr in list) {
				var kv = list[attr].split("=");
				if(kv[0] == key) {
					return kv[1];
				}
			}
			return "";
		}
	/*	//右侧固定懒存cookie  存入选择的图片
		$("#gowu").click(function(){
			var total = [];
			$(".u-flyers").each(function(index){
				total.push($(this).attr("src"));
				
			})
		
			setCookie("imglist",total,10);
		})*/
		
		
	});
})